/**
 * 
 */
package com.dingding.service.mall.dao.impl;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;
import org.hibernate.criterion.Criterion;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Component;

import com.dingding.common.core.base.dao.impl.BaseDaoImpl;
import com.dingding.common.core.beans.CommodityImage;
import com.dingding.facade.mall.dto.CommodityInfoPic;
import com.dingding.service.mall.dao.ICommodityInfoPicDao;

/**
 * @ClassName: CommodityInfoPicImpl
 * @Description:获取商品详情picDao
 * @author zhouxuan
 * @date 2016年3月30日 下午4:50:00
 */
@Component("commodityInfoPicDao")
public class CommodityInfoPicDaoImpl extends BaseDaoImpl<CommodityImage> implements ICommodityInfoPicDao {
	private Logger log = Logger.getLogger(this.getClass());

	/**
	 * @Title: getCommodityInfoPic
	 * @Description:获取商品详情图片
	 * @param @param
	 *            commodityId
	 * @author zhouxuan
	 * @return List<CommodityInfoPic>
	 */

	public List<CommodityInfoPic> getCommodityInfoPic(String commodityId) {

		List<CommodityImage> commodityImage = null;
		// 创建查询条件
		Criterion criterion = Restrictions.eq("commodityId", commodityId); // 商品ID

		try {
			commodityImage = this.queryCriteriaList(criterion);
		} catch (Exception e) {
			log.error("获取商品详情图片出错！CommodityInfoPicDaoImpl:getCommodityInfoPic", e);
		}

		if (commodityImage != null && commodityImage.size() > 0) {
			List<CommodityInfoPic> list = new ArrayList<CommodityInfoPic>();
			for (CommodityImage com : commodityImage) {
				CommodityInfoPic temp = new CommodityInfoPic();
				temp.setCommodityInfoPic(com.getCommodityPic());
				list.add(temp);
			}
			return list;
		}
		return null;
	}
}
